package light.head.controller.oa;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import light.head.constant.Parm;
import light.head.constant.Url;
import light.head.dao.oa.VehicleAssignDAO;
import light.head.dao.sys.OrganDAO;
import light.head.enm.RESULT;
import light.head.framework.base.SupporterController;
import light.head.framework.entity.PageBean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequestMapping(value = Url.C_VEHICLEASSIGN)
public class VehicleAssignController extends SupporterController{
	
	private VehicleAssignDAO vaDAO;
	private OrganDAO organDAO;
	

	@RequestMapping(value = Url.INIT)
	public ModelAndView init(HttpServletRequest request, HttpServletResponse response) throws Exception {
			return new ModelAndView(Url.ASSIGNRECORD_INIT);
	}
	
	@RequestMapping(value = Url.QUERY)
	public ModelAndView query(HttpServletRequest request, HttpServletResponse response) throws Exception {
		PageBean pb = createPageBean(request);
		Map<String, String> map = createQueryMapByParmName(request, Parm.DELETED, Parm.PLATE, Parm.OC,Parm.UN);
		Integer oc = organDAO.getRoot(cu_organCode(request)).getCode();
		if (vaDAO.findByMap(organDAO.getSonCodeList(oc),map, pb) == RESULT.SUCCESS) {
			request.setAttribute(Parm.PAGE_BEAN, pb);
		}
		return new ModelAndView(Url.ASSIGNRECORD_LIST);
	}

	/*@RequestMapping(value = Url.EDIT)
	public ModelAndView edit(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String code = request.getParameter(Parm.CODE);
		if (isNotNull(code)) {
			Vehicle ve = vehicleDAO.get(Integer.parseInt(code));
			request.setAttribute(Parm.VEHICLE, ve);
		}
		return new ModelAndView(Url.VEHICLEASSIGN_EDIT);
	}*/
	
	
	
	
	
	@Autowired
	public void setVaDAO(VehicleAssignDAO vaDAO) {
		this.vaDAO = vaDAO;
	}

	@Autowired
	public void setOrganDAO(OrganDAO organDAO) {
		this.organDAO = organDAO;
	}
	
}
